package com.xin.data.simbapesa.activity;

import android.annotation.SuppressLint;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.xin.data.simbapesa.SimbaApp;
import com.xin.data.simbapesa.api.U;
import com.xin.data.simbapesa.base.BaseActivity;
import com.xin.data.simbapesa.databinding.SimbaPrivacyActivityBinding;
import com.xin.data.simbapesa.utils.ViewUtils;

public class SimbaPrivacyActivity extends BaseActivity<SimbaPrivacyActivityBinding> {


    String url;

    @Override
    protected SimbaPrivacyActivityBinding initViewBinding(LayoutInflater inflater) {
        return SimbaPrivacyActivityBinding.inflate(inflater);
    }

    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void initView() {


        url = getIntent().getStringExtra("url");

        WebSettings webSettings = binding.webview.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setUseWideViewPort(true);
        webSettings.setLoadWithOverviewMode(true);
        webSettings.setDomStorageEnabled(true);
        webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        binding.webview.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                if (binding != null && getActivity() != null && !isFinishing() && !isDestroyed() && !TextUtils.isEmpty(url)) {
                    binding.webview.loadUrl(url);
                }
                return true;
            }

        });
        binding.webview.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onReceivedTitle(WebView view, String title) {
                super.onReceivedTitle(view, title);
                if (binding != null && getActivity() != null && !isFinishing() && !isDestroyed()) {
                    if (!TextUtils.isEmpty(title)) {
                        binding.tvTitle.setText(title);
                    }
                }
            }
        });
        binding.tvBk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ViewUtils.viewScale(v);
                finish();
            }
        });

        url = "https://www.baidu.com";

//        if (U.isCameroon) {
//            url = "https://sites.google.com/yesscom.net/simbapesaservicexaf";
//        } else {
//            url = "https://sites.google.com/yesscom.net/simbapesaservice";
//        }


        if (SimbaApp.getInstance().getAppInfo() != null && !TextUtils.isEmpty(SimbaApp.getInstance().getAppInfo().getPrivacyUrl())) {
            url = SimbaApp.getInstance().getAppInfo().getPrivacyUrl();
        }
        if (!url.isEmpty()) {
            binding.webview.loadUrl(url);
        }


    }

    @Override
    protected void initData() {

    }


}
